home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / windows / wdj1096.zip / ZOLMAN.ZIP / ZVBDLG.ZIP / ZSPIN.CPP < prev    next >
C/C++ Source or Header  |  1996-01-16  |  4KB  |  132 lines

  1. /*
  2.     File: ZSpin.cpp
  3.     Author: Raja
  4.     Date: Jan 16, 1996
  5.  
  6.     Implementation file for ZSpin class which handles Spin up and spin down
  7.     notifications.
  8. */
  9.  
  10. #include "stdafx.h"
  11. #include "zspin.h"
  12. #include "stdlib.h"
  13.  
  14. #define MAX_LENGTH 40
  15.  
  16. IMPLEMENT_DYNAMIC (ZSpin, CVBControl)
  17.  
  18. // Required for SubclassVBControl
  19. typedef CVBControl* __based((__segment)_self)* FAR* CVBHandle;  
  20.  
  21. #define new DEBUG_NEW
  22.  
  23. BEGIN_MESSAGE_MAP(ZSpin, CVBControl)
  24.     //{{AFX_MSG_MAP(ZSpin)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. // Register VBX events.
  29. UINT NEAR ZSPIN_VBN_SPINDOWN = AfxRegisterVBEvent("SPINDOWN");
  30. UINT NEAR ZSPIN_VBN_SPINUP = AfxRegisterVBEvent("SPINUP");
  31.  
  32. /**************************************************************************/
  33. // OnChildNotify - CWnd virtual function override
  34. // Refer to MFC documentation for details on parameters and return values
  35. // Handle the WM_VBXEVENT to process the SpinUp and SpinDown events.
  36. /**************************************************************************/
  37.  
  38. BOOL ZSpin::OnChildNotify (UINT message, WPARAM wParam, LPARAM lParam,
  39.                         LRESULT *pLResult)
  40. {
  41.     AFX_VBXEVENTPARAMS *pParams;
  42.     int nVal;       
  43.     char szBuffer [MAX_LENGTH];
  44.     
  45.     switch (message) {
  46.         case WM_VBXEVENT:
  47.             pParams = (AFX_VBXEVENTPARAMS FAR*)lParam;
  48.             if (pParams->nNotifyCode == ZSPIN_VBN_SPINUP) {
  49.                 ::GetWindowText (m_hWndEdit, szBuffer, MAX_LENGTH);
  50.                 nVal = atoi (szBuffer);
  51.                 wsprintf (szBuffer, "%d", nVal + 1);
  52.                 ::SetWindowText (m_hWndEdit, szBuffer);
  53.             }
  54.             else if (pParams->nNotifyCode == ZSPIN_VBN_SPINDOWN) {
  55.                 ::GetWindowText (m_hWndEdit, szBuffer, MAX_LENGTH);
  56.                 nVal = atoi (szBuffer);
  57.                 wsprintf (szBuffer, "%d", nVal - 1);
  58.                 ::SetWindowText (m_hWndEdit, szBuffer);
  59.             }
  60.             return TRUE;
  61.     }
  62.     return CVBControl::OnChildNotify(message, wParam, lParam, pLResult);
  63. }
  64.  
  65. /**************************************************************************/
  66. // SubclassVBControl - copied from subvbctl.cpp in SUBVBX project (MSDN).
  67. // Parameters: Parent CWnd pointer, control id, whether embedded (TRUE).
  68. // Returns: TRUE on success, FALSE otherwise.
  69. // Note: Slight changes from original - return values.
  70. /**************************************************************************/
  71.  
  72. BOOL ZSpin::SubclassVBControl(CWnd* pParent, UINT idChild, 
  73.                     BOOL bEmbedded)
  74. {
  75.     ASSERT(pParent != NULL);
  76.     ASSERT(idChild != 0 && idChild != -1);
  77.     
  78. // Get the existing CVBControl.  Cast it to this class type
  79. // so that we will have access to the protected data
  80.     ZSpin * pControl = (ZSpin *)pParent->GetDlgItem (idChild);
  81.     if (!pControl)
  82.         return FALSE;
  83.     ASSERT(pControl->IsKindOf(RUNTIME_CLASS(CVBControl)));
  84.     
  85.     // Copy over all of the appropriate data
  86.     m_pModel = pControl->m_pModel;
  87.  
  88.     m_bRecreating = pControl->m_bRecreating;
  89.     m_bInPostNcDestroy = pControl->m_bInPostNcDestroy;
  90.     m_bLoading = pControl->m_bLoading;
  91.     m_nCursorID = pControl->m_nCursorID;
  92.     
  93.     m_nInitialStack = pControl->m_nInitialStack;
  94.     m_nRecursionLevel = pControl->m_nRecursionLevel;
  95.     m_bStackFault = pControl->m_bStackFault;
  96.     m_nFaultRecurse = pControl->m_nFaultRecurse;
  97.  
  98.     m_hbrBkgnd = pControl->m_hbrBkgnd;
  99.     m_hFontCreated = pControl->m_hFontCreated;
  100.     m_hcurMouse = pControl->m_hcurMouse;
  101.     m_hCtl = pControl->m_hCtl;
  102.     m_clrBkgnd = pControl->m_clrBkgnd;
  103.     m_clrFore = pControl->m_clrFore;
  104.     m_rectCreate = pControl->m_rectCreate;
  105.     m_strTag = pControl->m_strTag;
  106.  
  107.     m_bAutoDelete = !bEmbedded;
  108.  
  109.     // Clear data in the old CVBControl that would cause problems   
  110.     pControl->m_hFontCreated = NULL;
  111.     pControl->m_hbrBkgnd = NULL;
  112.     pControl->m_hcurMouse = NULL;
  113.     pControl->m_pModel = NULL;
  114.     pControl->m_hCtl   = NULL;
  115.     CVBHandle hpControl = (CVBHandle) m_hCtl;
  116.     **hpControl = this;
  117.     
  118.     pControl->m_hFontCreated=NULL;
  119.     pControl->m_hbrBkgnd=NULL;
  120.     pControl->m_hcurMouse=NULL;
  121.  
  122.     // Transfer hWnd
  123.     Attach(pControl->Detach());
  124.     
  125.     // Delete old object if necessary
  126.     if (pControl->m_bAutoDelete)
  127.         delete pControl;        
  128.  
  129.     return TRUE;
  130. }
  131.  
  132.